// format the dubinski 1995 file with 81920 bodies

#include <stdio.h>
#include <stdlib.h>

#define BUF_SIZE 1024 // buffer size
#define BUF_CNT  80 // buffer count = 81920/1024

int main(void) {

  float buf[BUF_SIZE*7];
	unsigned int *ptr;;
  int i, j, k;
  FILE *fp_bin;
	FILE *fp_sim;

	ptr = (unsigned int *)buf;

  fp_sim = fopen("nbody_81920.sim", "w");
  fp_bin = fopen("nbody_81920.dat", "w");
  for (i=0; i<BUF_CNT; i++) {
    for (j=0; j<BUF_SIZE; j++) {
      for (k=0; k<7; k++) {
        scanf("%f", buf+j*7+k);
				fprintf(fp_sim, "%04X ", *(ptr+j*7+k));
			}
			fprintf(fp_sim, "\n");
		}
    fwrite(buf, sizeof(float)*7, BUF_SIZE, fp_bin);
  }

  fclose(fp_bin);
  fclose(fp_sim);
  printf("Done!\n");

  return 0;
}
